package com.redribbon.droidnoise;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class ServerOptions extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.server_1);
        
       	final Button s1_back_button = (Button) findViewById(R.id.server_1_back_button);
        s1_back_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	finish();
            }
        });
        
       	final Button s1_next_button = (Button) findViewById(R.id.server_1_next_button);
       	s1_next_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	try {
                	Intent startController = new Intent(ServerOptions.this, ServerController.class);            		
                	NoiseConstants.server_station_name = (((TextView)findViewById(R.id.server_1_station_field)).getText()).toString();
                	NoiseConstants.server_port_number = Integer.parseInt((((TextView)findViewById(R.id.server_1_port_field)).getText()).toString());
            		startActivity(startController);
            	} catch (NumberFormatException e) {
                	Log.e(getClass().getName(), "Bad port number", e);
                	showError("Bad Port Number");
                }
            }
        });
       	
       
	}
	private void showError(String msg) {
   		Toast.makeText(this, msg, Toast.LENGTH_SHORT);
   	}
}
